// 公用的
import _ from 'lodash';
//#region 单位角色
export const companyRole_data = [{
        id: 'TRAVEL_AGENCY',
        val: null,
        text: '旅行社',
        other: 'c-red'
    },
    {
        id: 'CAR_TEAM',
        val: null,
        text: '车队',
        other: 'c-red'
    },
    {
        id: 'RENT_COMPANY',
        val: null,
        text: '租赁公司',
        other: 'c-red'
    },
    {
        id: 'HOTEL',
        val: null,
        text: '酒店',
        other: 'c-red'
    },
    {
        id: 'CONFERENCE_COMPANY',
        val: null,
        text: '会务公司',
        other: 'c-green'
    }

]
//#endregion

//#region 图片地址  此处可以通过判断环境变量设置开发与生产的不同地址
export const ImageUrl = 'https://cba360.com'
//  `${import.meta.env.VITE_SERVE.replace('kcbServiceApi', 'kcbservice-admin')}`
//#endregion

//#region 上传图片的地址
// 测试
// export const ImageUrl_upload = '/api/back/file/myUploadFiles'
//  线上
export const ImageUrl_upload = '/kcbServiceApi/back/file/myUploadFiles'
//#endregion

//#region 文件类型
export const FileType = [{
        "id": "ROUTE_TITLE_IMG",
        "val": null,
        "text": "行程标题图片",
        "other": "c-gray"
    },
    {
        "id": "ROUTE_POSTER_IMG",
        "val": null,
        "text": "行程海报图片",
        "other": "c-green"
    },
    {
        "id": "ROUTE_EXPLAIN_IMG",
        "val": null,
        "text": "行程说明图片",
        "other": "c-green"
    },
    {
        "id": "ROUTE_DETAIL_CON_IMG",
        "val": null,
        "text": "行程详情内容图片",
        "other": "c-green"
    },
    {
        "id": "COMPANY_DETAIL_IMG",
        "val": null,
        "text": "单位详情图片",
        "other": "c-green"
    },
    {
        "id": "HEAD_IMG",
        "val": null,
        "text": "头像图片",
        "other": "c-green"
    },
    {
        "id": "IDCARD_FRONT_IMG",
        "val": null,
        "text": "身份证正面照",
        "other": "c-green"
    },
    {
        "id": "IDCARD_BACK_IMG",
        "val": null,
        "text": "身份证背面照",
        "other": "c-green"
    },
    {
        "id": "BUSINESS_IMG",
        "val": null,
        "text": "经营许可证",
        "other": "c-green"
    },
    {
        "id": "BUSLICENSE_IMG",
        "val": null,
        "text": "工商营业执照",
        "other": "c-green"
    },
    {
        "id": "BACK_SET_DATA_IMG",
        "val": null,
        "text": "其他",
        "other": "c-blue"
    },
    {
        "id": "HEAD_BANNER_IMG",
        "val": null,
        "text": "首页轮播图",
        "other": "c-blue"
    },
    {
        "id": "INVITATION_IMG",
        "val": null,
        "text": "邀请码图片",
        "other": "c-blue"
    },
    {
        "id": "NOTICE_DETAIL_IMG",
        "val": null,
        "text": "公告详情图片",
        "other": "c-blue"
    },
    {
        "id": "GROUP_QRCODE_IMG",
        "val": null,
        "text": "群二维码图片",
        "other": "c-blue"
    },
    {
        "id": "PERSONAL_QRCODE_IMG",
        "val": null,
        "text": "个人微信二维码图片",
        "other": "c-blue"
    }
]

//#endregion

//#region 高德地图
export const securityJsCode = 'aac7d76ba0a5dbde956c5694d87ee792' // 安全秘钥

export const key = 'bb28dd7fa15afc231362b033739d9420' // key
//#endregion


/**
 * 线型数据转树形数据
 * @param list 欲处理的数据列表
 * @param pname 父级标志名称 如：pid
 */
export const line2treeData = (list, pname) => {

    if (!list || list.length == 0) return list;

    let map = {};
    // 遍历第一遍，以id为键，保存起来，方便获取
    list.forEach(it => {
        map[it.id] = it;
    });
    // console.log('1.处理后的数据', map);

    // 遍历第二遍，为父级添加子集   
    for (let it in map) {
        let c = map[it],
            p = map[c[pname]];

        if (p) {
            if (p.children) {
                p.children.push(c);
            } else {
                p.children = [c];
            }
        } else { // 不存在，则保存为顶级（去掉这里，不然elementui的cascader组件取不了没有子集的选项值）
            // c.children = [];
        }
    }

    // console.log('2.处理后的数据', map);

    // 第三遍遍历，排除不是父级的数据
    let reslist = [];
    for (let it in map) {
        let c = map[it];
        // 父级不存在的对象保存
        if (!map[c[pname]]) reslist.push(map[it]);
    }

    // console.log('3.处理后的数据', reslist);
    return reslist;
}


export const tree2lineData = (treeList, totalNode = []) => {
    for (let i in treeList) {
        totalNode.push(treeList[i]);
        if (treeList[i].children) {
            tree2lineData(treeList[i].children, totalNode);
        }
    }
    return totalNode;
}

// 深度拷贝对象

export const scopy = (obj) => {
    return _.cloneDeep(obj);
}
